package com.gitee.ywj1352.ds.web;

import org.springframework.lang.Nullable;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.concurrent.TimeoutException;

public class CircuitBreakerHanderInterceptor  implements HandlerInterceptor {

    @Override
    public void afterCompletion(HttpServletRequest request,
                                HttpServletResponse response,
                                Object handler, @Nullable Exception ex)
            throws Exception {
        if ("/say4".equals(request.getRequestURI())&&ex instanceof TimeoutException){
            PrintWriter writer = response.getWriter();
            writer.write(errorContent("ywj"));
        }
    }

    public String errorContent(String message){
        return message;
    }
}
